//
//  DenoiseView.m
//  LINNER
//
//  Created by Kendama on 2017/10/11.
//  Copyright © 2017年 Kendama. All rights reserved.
//

#import "DenoiseView.h"

@implementation DenoiseView

#pragma mark -- 点击事件
- (void)didClickWindButtonWithDelegate:(BOOL)delegate
{
    self.powerButton.selected = NO;
    self.windButton.selected = YES;
    self.indoorButton.selected = NO;
    self.tripButton.selected = NO;
    self.monitoringButton.selected = NO;

    if (!delegate)
    {
        if ([self.delegate respondsToSelector:@selector(denoiseViewSelected:)])
        {
            [self.delegate denoiseViewSelected:1];
        }
    }

}

- (void)didClickPowerButtonWithDelegate:(BOOL)delegate
{
    self.powerButton.selected = YES;
    self.windButton.selected = NO;
    self.indoorButton.selected = NO;
    self.tripButton.selected = NO;
    self.monitoringButton.selected = NO;
    
    if (!delegate)
    {
        if ([self.delegate respondsToSelector:@selector(denoiseViewSelected:)])
        {
            [self.delegate denoiseViewSelected:0];
        }
    }

}

- (void)didClickIndoorButtonWithDelegate:(BOOL)delegate
{
    self.powerButton.selected = NO;
    self.windButton.selected = NO;
    self.indoorButton.selected = YES;
    self.tripButton.selected = NO;
    self.monitoringButton.selected = NO;
    
    if (!delegate)
    {
        if ([self.delegate respondsToSelector:@selector(denoiseViewSelected:)])
        {
            [self.delegate denoiseViewSelected:2];
        }
    }

}

- (void)didClickTripButtonWithDelegate:(BOOL)delegate
{
    self.powerButton.selected = NO;
    self.windButton.selected = NO;
    self.indoorButton.selected = NO;
    self.tripButton.selected = YES;
    self.monitoringButton.selected = NO;
    
    if (!delegate)
    {
        if ([self.delegate respondsToSelector:@selector(denoiseViewSelected:)])
        {
            [self.delegate denoiseViewSelected:3];
        }
    }

}

- (void)didClickMonitoringButtonWithDelegate:(BOOL)delegate
{
    self.powerButton.selected = NO;
    self.windButton.selected = NO;
    self.indoorButton.selected = NO;
    self.tripButton.selected = NO;
    self.monitoringButton.selected = YES;
    
    if (!delegate)
    {
        if ([self.delegate respondsToSelector:@selector(denoiseViewSelected:)])
        {
            [self.delegate denoiseViewSelected:4];
        }
    }

}


#pragma mark -- 事件处理
- (void)setDenoiseViewSelected:(NSInteger)index
{
    switch (index) {
        case 0:
        {
            [self didClickPowerButtonWithDelegate:YES];
        }
            break;
        case 1:
        {
            [self didClickWindButtonWithDelegate:YES];
        }
            break;
        case 2:
        {
            [self didClickIndoorButtonWithDelegate:YES];
        }
            break;
        case 3:
        {
            [self didClickTripButtonWithDelegate:YES];
        }
            break;
        case 4:
        {
            [self didClickMonitoringButtonWithDelegate:YES];
        }
            break;
            
        default:
            break;
    }
}

#pragma mark -- 懒加载
- (UIButton *)windButton
{
    if(!_windButton)
    {
        UIView *superView = self;
        _windButton = [[UIButton alloc]init];
        [superView addSubview:_windButton];
        [_windButton setImage:[UIImage imageNamed:MyNSLocalizedString(@"windy_nor_zh")] forState:UIControlStateNormal];
        [_windButton setImage:[UIImage imageNamed:MyNSLocalizedString(@"windy_sel_zh")] forState:UIControlStateSelected];
        [_windButton addTarget:self action:@selector(didClickWindButtonWithDelegate:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _windButton;
}
- (UIButton *)powerButton
{
    if(!_powerButton)
    {
        UIView *superView = self;
        _powerButton = [[UIButton alloc]init];
        [superView addSubview:_powerButton];
        [_powerButton setImage:[UIImage imageNamed:@"power_nor"] forState:UIControlStateNormal];
        [_powerButton setImage:[UIImage imageNamed:@"power_sel"] forState:UIControlStateSelected];
        [_powerButton addTarget:self action:@selector(didClickPowerButtonWithDelegate:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _powerButton;
}
- (UIButton *)indoorButton
{
    if(!_indoorButton)
    {
        UIView *superView = self;
        _indoorButton = [[UIButton alloc]init];
        [superView addSubview:_indoorButton];
        [_indoorButton setImage:[UIImage imageNamed:MyNSLocalizedString(@"indoor_nor_zh")] forState:UIControlStateNormal];
        [_indoorButton setImage:[UIImage imageNamed:MyNSLocalizedString(@"indoor_sel_zh")] forState:UIControlStateSelected];
        [_indoorButton addTarget:self action:@selector(didClickIndoorButtonWithDelegate:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _indoorButton;
}

- (UIButton *)tripButton
{
    if(!_tripButton)
    {
        UIView *superView = self;
        _tripButton = [[UIButton alloc]init];
        [superView addSubview:_tripButton];
        [_tripButton setImage:[UIImage imageNamed:MyNSLocalizedString(@"travel_nor_zh")] forState:UIControlStateNormal];
        [_tripButton setImage:[UIImage imageNamed:MyNSLocalizedString(@"travel_sel_zh")] forState:UIControlStateSelected];
        [_tripButton addTarget:self action:@selector(didClickTripButtonWithDelegate:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _tripButton;
}
- (UIButton *)monitoringButton
{
    if(!_monitoringButton)
    {
        UIView *superView = self;
        _monitoringButton = [[UIButton alloc]init];
        [superView addSubview:_monitoringButton];
        [_monitoringButton setImage:[UIImage imageNamed:MyNSLocalizedString(@"monitor_nor_zh")] forState:UIControlStateNormal];
        [_monitoringButton setImage:[UIImage imageNamed:MyNSLocalizedString(@"monitor_sel_zh")] forState:UIControlStateSelected];
        [_monitoringButton addTarget:self action:@selector(didClickMonitoringButtonWithDelegate:) forControlEvents:UIControlEventTouchUpInside];

    }
    return _monitoringButton;
}



- (void)masLayoutSubview
{
    __weak UIView *superView = self;
    [self.powerButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(superView);
    }];
    
    [self.windButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.powerButton.mas_top).with.offset(px1920Height(-30));
        make.right.mas_equalTo(self.powerButton.mas_left).with.offset(px1080Width(-30));
    }];
    
    [self.indoorButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.powerButton.mas_top).with.offset(px1920Height(-30));
        make.left.mas_equalTo(self.powerButton.mas_right).with.offset(px1080Width(30));
    }];
    
    [self.tripButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.powerButton.mas_bottom).with.offset(px1920Height(30));
        make.right.mas_equalTo(self.powerButton.mas_left).with.offset(px1080Width(-30));
    }];
    
    [self.monitoringButton mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.powerButton.mas_bottom).with.offset(px1920Height(30));
        make.left.mas_equalTo(self.powerButton.mas_right).with.offset(px1080Width(30));
    }];
}

@end
